package cn.jhc.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import cn.jhc.bean.Role;
import cn.jhc.factory.ConnectionFactory;

public class RoleDAO {
	
	public List<Role> getGroups(){
		List<Role> list = new ArrayList<Role>();
		Connection cnn = (Connection) ConnectionFactory.getConnection();
		ResultSet rs = null;
		Statement statement = null;
		
		String sql = "select id,rolename from role";
		try {
			statement = (Statement) cnn.createStatement();
			rs = statement.executeQuery(sql);
		while(rs.next()){
			int id = rs.getInt(1);
			String rolename = rs.getString(2);
			Role role = new Role(id,rolename);
			list.add(role);
		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				statement.close();
				cnn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}

}
